package com.jiecao.news.jiecaonews.util.view;

import com.jiecao.news.jiecaonews.R;

import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.TranslateAnimation;

public class SlideIt {
	private ViewGroup m_viewGroup;
	private View showButton;
	float dy;
	public SlideIt(ViewGroup viewGroup){
		m_viewGroup = viewGroup;
	}
	public void slideview(final float x, final float y,long duration,long offset, View showButton ) {
		int left = m_viewGroup.getLeft();
        int top = m_viewGroup.getTop();
        TranslateAnimation animation;
         dy = y;
        if(left==0&&top==0){
        	dy =y<0?y:-y;
        	animation = new TranslateAnimation(0, x, 0, dy);
        	if(showButton!=null){
        		showButton.setBackgroundResource(R.drawable.btn_corner201);
        	}
        }else{
        	dy =y<0?-y:y;
        	animation = new TranslateAnimation(0, x, 0, dy);
        	if(showButton!=null){
        		showButton.setBackgroundResource(R.drawable.btn_corner01);
        	}
        }
        System.out.println(left);
        System.out.println(top);
        
//	    animation.setInterpolator(new OvershootInterpolator());
	    animation.setDuration(duration);
	    animation.setStartOffset(offset);
	    animation.setAnimationListener(new Animation.AnimationListener() {
	        @Override
	        public void onAnimationStart(Animation animation) {
	        }
	        
	        @Override
	        public void onAnimationRepeat(Animation animation) {
	        }
	        
	        @Override
	        public void onAnimationEnd(Animation animation) {
	            int left = m_viewGroup.getLeft()+(int)x;
	            int top = m_viewGroup.getTop()+(int)dy;
	            int width = m_viewGroup.getWidth();
	            int height = m_viewGroup.getHeight();
	            m_viewGroup.clearAnimation();
	            m_viewGroup.layout(left, top, left+width, top+height);
	        }
	    });
	    m_viewGroup.startAnimation(animation);
	}
}
